//
//  LHTabViewController.swift
//  weibao
//
//  Created by 李浩 on 16/4/5.
//  Copyright © 2016年 李浩. All rights reserved.
//

import UIKit

class LHTabViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

       
        addChildViewController(LHHomeViewController(),image:"tabbar_home",title:"首页")
        
        addChildViewController(LHMessageViewController(),image:"tabbar_message_center",title:"消息")
        
        addChildViewController(LHFineViewController(),image:"tabbar_discover",title:"发现")
        
        addChildViewController(LHSettingViewController(),image:"tabbar_profile",title:"设置")
        
        
        let LHTab = LHTabBar()
        
        //使用Kvc 动态赋值
        setValue(LHTab, forKey: "tabBar")
//
        
        LHTab.composeBtn.addTarget(self, action:"btnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        
    }

    
    func btnClick(){
    
        
        print("点击了")
    
    
    }
    
 

    //重载
   
     func addChildViewController(childController: UIViewController,image : String,title : String) {
        
        
        childController.tabBarItem.image = UIImage(named: image)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
      
        //修改系统渲染色
        //appearance 能够获取当前的UITabBar 或者UINavgationBar实力对象
        
        //我们可以通过修改 UITabBar.appearance().tintColor 来改变系统的默认蓝色
        
        
        UITabBar.appearance().tintColor=UIColor.orangeColor()
      
        
        //设置标题
        
        childController.title = title
        
        //设置导航栏
        
        let nav = UINavigationController(rootViewController: childController)
        
        
        addChildViewController(nav)
        
        
    }

 

}
